package com.whp.openapi.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
 * 统一返回数据类型（利于前后端的交互与UI的展示）
 * @author whp
 * @date 2021/11/23
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class ResponseResult<T> {
    private boolean status; //响应状态
    private String msg; //显示信息
    private T t; //响应数据

    /**
     * 响应成功
     * @return
     */
    public static ResponseResult getSuccess() {
        return new ResponseResult(ResponseCode.SUCCESS.isStatus(), ResponseCode.SUCCESS.getCommon(), null);
    }
    public static ResponseResult getSuccess(String msg) {
        return new ResponseResult(true, msg, null);
    }
    public static <T> ResponseResult getSuccess(T t) {
        return new ResponseResult(true, null, t);
    }
    public static <T> ResponseResult getSuccess(String msg, T t) {
        return new ResponseResult(true, msg, t);
    }

    /**
     * 响应失败
     * @return
     */
    public static ResponseResult getFail() {
        return new ResponseResult(false, null, null);
    }
    public static ResponseResult getFail(String msg) {
        return new ResponseResult(false, msg, null);
    }
    public static <T> ResponseResult getFail(T t) {
        return new ResponseResult(false, null, t);
    }
    public static <T> ResponseResult getFail(String msg, T t) {
        return new ResponseResult(false, msg, t);
    }
}
